<?php

namespace backend\models;

use Yii;

class AuthItem extends \common\models\AuthItem
{    
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return array_merge([
            [['rule_name'], 'default', 'value'=>null]  // 把空字符串转为null以免外键约束出错
        ], parent::rules());
    }
    
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            [
                'class' => \yii\behaviors\TimestampBehavior::className(),
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'name' => '名称',
            'type' => '类型',
            'description' => '说明',
            'rule_name' => '规则',
            'data' => '附加数据',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }
    
    /**
     * Gets query for [[Users]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getUsers()
    {
        return parent::getUsers()->addOrderBy('username');
    }
    
    /**
     * Gets query for [[Children]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getChildren()
    {
        return parent::getChildren()->addOrderBy('type,name');
    }

    /**
     * Gets query for [[Parents]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getParents()
    {
        return parent::getParents()->addOrderBy('type,name');
    }
}
